package com.gh.ggkt.vod.listen;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.atguigu.ggkt.model.vod.Subject;
import com.atguigu.ggkt.vo.vod.SubjectEeVo;
import com.gh.ggkt.vod.mapper.SubjectMapper;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;

/**
 * @author Eric Fang
 * @date 2022/9/11 11:55
 */
@Slf4j
@NoArgsConstructor
public class SubjectExcelListener extends AnalysisEventListener<SubjectEeVo> {

    private SubjectMapper subjectMapper;

    public SubjectExcelListener(SubjectMapper subjectMapper) {
        this.subjectMapper = subjectMapper;
    }

    /**
     * 读取到每一行的内容
     * @param subjectEeVo
     * @param analysisContext
     */
    @Override
    public void invoke(SubjectEeVo subjectEeVo, AnalysisContext analysisContext) {
        Subject subject = new Subject();
        BeanUtils.copyProperties(subjectEeVo, subject);
        subjectMapper.insert(subject);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
